#include "LinkStack.h"

LinkStack *LinkStack::Init_LinkStack() {
    this->head.next = NULL;
    this->size = 0;
    return this;
}

void LinkStack::Push_LinkStack(LinkNode *data) {
    if(this == NULL || data == NULL) return;

    data->next = this->head.next;
    this->head.next = data;
    this->size++;
}

LinkNode *LinkStack::Pop_LinkStack() {
    if(this == NULL) return  NULL;
    if(this->size == 0) return NULL;

    LinkNode* save = this->head.next;
    this->head.next = save->next;
    save->next = NULL;

    this->size--;
    return save;
}

LinkNode *LinkStack::Top_LinkStack() {
    if(this == NULL) return  NULL;
    if(this->size == 0) return NULL;

    return this->head.next;
}

int LinkStack::Size_LinkStack() {
    if(this == NULL) return  -1;
    return this->size;
}

void LinkStack::Clear_LinkStack() {
    if(this == NULL) return;

    this->head.next = NULL;
    this->size = 0;
}

void LinkStack::FreeSpace_LinkStack() {
    if(this == NULL) return;

    delete(this);
}
